Data Science for Business With R by Jeffrey S. Saltz & Jeffrey M. Stanton

Data Science for Business With R by Jeffrey S. Saltz & Jeffrey M. Stanton

Author:Jeffrey S. Saltz & Jeffrey M. Stanton
Language: eng
Format: epub
Published: 2021-02-14T20:34:49.612924+00:00


You can see we saved the visualization in a variable ("g"), so we can add another layer. Let’s use that stored visualization variable and add some labeling to show the name of each state. Note that we defined some additional aesthetics for the text (the size, and the vertical adjustment of where to place the text).

g + geom_text(size=3, vjust=2) + aes(label=stateName)

By examining this scatterplot, we see that some states are outliers (some have large populations and some have much smaller populations). For example, the District of Columbia has a very small population and a small absolute population change, but has the largest percent increase in population. Texas is a very large state and has both a high absolute and high percentage increase in population.

This chart has now become very cluttered. Let’s clean it up by doing several actions. First, let’s define a set of key (or important) states. These are the states that have a percentage change of at least 1% and a population change of at least 100,000 people. With these criteria, we define a new column in the dfStates dataframe, keyState, to be true if that state fits our defined criteria of percentage and population change. In the scatter chart, we show the key states by defining the shape of the symbol within the scatterplot to dependent on the keyState column. We also only show the text for the key states. Next, we clean up the format of the color key, defining the three values to be shown in the key as well as formatting the numbers to include commas, so the numbers are easier to see. Finally, we change the color scale to range from white to black.

#define the criteria to show the text for the state

minPerChange <- 1

minPopChange <- 100000



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.